#ifndef HOSTILERELATIONSPANEL_H_INCLUDE_
#define HOSTILERELATIONSPANEL_H_INCLUDE_

#include "common.h"
#include <wx/dataview.h>
#include "nodemanager/wnodemanager.h"
#include "nodemanager/crouteconditions.h"
#include "signal.hpp"

class hostilerelationspanel;

class HostilerelationParamEditPanel : public wxPanel
{
public:
    HostilerelationParamEditPanel(wxWindow* parent);
    ~HostilerelationParamEditPanel();

    // 设置当前编辑区段
    inline void setRouteCondiItem(tagRouteCondiItem *pCondiItem)
    {
        mRouteCondiItem=pCondiItem;
    }
    // 得到当前编辑区段
    inline tagRouteCondiItem* getRouteCondiItem(void) { return mRouteCondiItem; }
    // 挂接道岔改变信号槽
    void sig_ProcessItemChanged(hostilerelationspanel *phostilerelationspanel);
    // 获取所有参数数据
    std::map<wxString, wxString> GetData() const;
    // 设置参数数据
    void SetData(const std::map<wxString, wxString>& data);
    // 重置所有参数
    void resetAllData(void);

    // 设置敌对信号
    inline void setconflictsignal(wxString decString)
    {
        m_conflictsignalText->SetValue(decString);
        m_lastChangedData["conflictsignal"] = decString;
    }
    // 得到敌对信号
    inline wxString getconflictsignal(void) { return m_conflictsignalText->GetValue(); }
    // 得到敌对道岔
    inline void setconflictswitch(wxString decString)
    {
        m_conflictswitchText->SetValue(decString);
        m_lastChangedData["conflictswitch"] = decString;
    }
    // 得到敌对道岔
    inline wxString getconflictswitch(void) { return m_conflictswitchText->GetValue(); }
    // 得到联锁道岔
    inline void setfollowswitch(wxString decString)
    {
        m_followswitchText->SetValue(decString);
        m_lastChangedData["followswitch"] = decString;
    }
    // 得到联锁道岔
    inline wxString getfollowswitch(void) { return m_followswitchText->GetValue(); }

private:
    void InitUI();

    void OnstartlightTextChanged(wxCommandEvent& event);
    void OnstartlightTextKillFocus(wxFocusEvent& event);
    void OnstartlightTextEnter(wxCommandEvent& event);

    void OnendlightTextChanged(wxCommandEvent& event);
    void OnendlightTextKillFocus(wxFocusEvent& event);
    void OnendlightTextEnter(wxCommandEvent& event);

    void OnconflictsignalTextChanged(wxCommandEvent& event);
    void OnconflictsignalTextKillFocus(wxFocusEvent& event);
    void OnconflictsignalTextSetFocus(wxFocusEvent& event);
    void OnconflictsignalTextEnter(wxCommandEvent& event);

    void OnconflictswitchTextChanged(wxCommandEvent& event);
    void OnconflictswitchTextKillFocus(wxFocusEvent& event);
    void OnconflictswitchTextSetFocus(wxFocusEvent& event);
    void OnconflictswitchTextEnter(wxCommandEvent& event);

    void OnfollowswitchTextChanged(wxCommandEvent& event);
    void OnfollowswitchTextKillFocus(wxFocusEvent& event);
    void OnfollowswitchTextSetFocus(wxFocusEvent& event);
    void OnfollowswitchTextEnter(wxCommandEvent& event);

private:
    tagRouteCondiItem *mRouteCondiItem;
    sigslot::signal4<tagRouteCondiItem*,int,wxString,wxString> sig_item_change;
    sigslot::signal2<tagRouteCondiItem*,int> sig_item_selected;
    std::map<wxString, wxString> m_lastChangedData;

    wxStaticText* m_startlightLabel;
    wxComboBox* m_startlightText;
    bool m_startlightTextEditFinished;

    wxStaticText* m_endlightLabel;
    wxComboBox* m_endlightText;
    bool m_endlightTextEditFinished;

    wxStaticText* m_conflictsignalLabel;
    wxTextCtrl* m_conflictsignalText;
    bool m_conflictsignalEditFinished;

    wxStaticText* m_conflictswitchLabel;
    wxTextCtrl* m_conflictswitchText;
    bool m_conflictswitchEditFinished;

    wxStaticText* m_followswitchLabel;
    wxTextCtrl* m_followswitchText;
    bool m_followswitchEditFinished;
};

class HostilerelationParamPanel : public wxPanel
{
public:
    HostilerelationParamPanel(wxWindow *parent);
    ~HostilerelationParamPanel();

    // 设置当前编辑区段
    inline void setRouteCondiItem(tagRouteCondiItem *pRouteCondiItem)
    {
        mRouteCondiItem=pRouteCondiItem;
    }
    // 得到当前编辑结点
    inline tagRouteCondiItem* getRouteCondiItem(void) { return mRouteCondiItem; }
    // 挂接道岔改变信号槽
    void sig_ProcessRangeItemChanged(hostilerelationspanel *phostilerelationspanel);
    void clearAllData(void);
    void initAllItem(int itemIndex);
    void addData(const wxVector<wxVariant> data);
    // 重置所有参数
    void resetAllData(void);
    // 重新加载所有的结点
    void reloadAllNodes(void);

private:
    void OnEditingDone(wxDataViewEvent& event);
    void OnRightClick(wxDataViewEvent& event);

    void OnDeleteRange(wxCommandEvent& event);
    void OnAddNewRange(wxCommandEvent& event);

private:
    tagRouteCondiItem *mRouteCondiItem;
    sigslot::signal2<wxString,wxString> sig_range_change;
    sigslot::signal2<int,tagRouteCondiItem*> sig_add_del_change;
    int m_curSelecteditemindex;

    wxDataViewCtrl* m_dvc;
    wxDataViewListStore* m_store;
};

class hostilerelationspanel : public sigslot::has_slots<>,
                              public wxPanel
{
public:
    hostilerelationspanel(wxWindow *parent);
    ~hostilerelationspanel();

    void addRouteCondiItem(tagRouteCondiItem* routecondi);
    void addData(const wxVector<wxVariant> data);

    void slot_ProcessItemChanged(tagRouteCondiItem *pRouteCondiItem,int itemindex,wxString olddata,wxString newdata);
    void slot_ProcessItemRangeChanged(wxString oldparams,wxString newparams);
    void slot_ProcessItemSelected(tagRouteCondiItem *pRouteCondiItem,int itemindex);
    void slot_ProcessItemAddAndDelete(int operType,tagRouteCondiItem *pRouteCondiItem);

private:
    void OnSelectionChanged(wxDataViewEvent& event);
    void OnRightClick(wxDataViewEvent& event);

    void OnDeleteSect(wxCommandEvent& event);
    void OnAddNewSect(wxCommandEvent& event);

private:
    wxDataViewCtrl* m_dvc;
    wxDataViewListStore* m_store;

    int m_curSelecteditemindex;
    HostilerelationParamEditPanel *m_HostilerelationParamEditPanel;
    HostilerelationParamPanel *m_HostilerelationParamPanel;
};

#endif // HOSTILERELATIONSPANEL_H
